<%@ page import="pojo.User" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
    <title>el表达式jstl</title>
</head>
<body>

<%
    pageContext.setAttribute("key", "1");
    request.setAttribute("key", "2");
    session.setAttribute("key", "3");
    application.setAttribute("key", "4");
%>

${key}

<%
    request.setAttribute("rkey", "value");
    request.setAttribute("user", new User("张三", 22));
    pageContext.setAttribute("key", "pvalue");
    request.setAttribute("key", "svalue");
%>

<%
    request.setAttribute("user", new User("张三", 22));
%>

${requestScope.user.name}
${requestScope.user.age}

${requestScope.rkey}
${requestScope.user.name}
${requestScope.user.age}
${key}
<%--数学运算--%>
${(1+2*3+1)/2%3}
<%--关系运算--%>
${1>4}
<%-->  >=  <  <=  ==  !=
gt ge  lt le  eq  !=--%>
<%--逻辑运算--%>
${true||false}
<%--三元表达式--%>
${3>1?"大于":"小于"}
<%--获取请求参数中的值--%>
${param.age}
<%--获取值是列表的参数--%>
${paramValues.age[0]}
${paramValues.age[1]}

<%--page-->request-->session-->application--%>
<c:set scope="session" var="cskey" value="c标签设置session"/>
<c:remove scope="session" var="cskey"/>
删除标签:::${cskey}
<c:set scope="request" var="crage" value="1"/>
<c:set scope="request" var="crage" value="${crage+2}"/>
el表达式写入值到set标签${crage}
<c:if test="${3>2}">
    3>2
</c:if>

<c:choose>
    <c:when test="${crage==1}">
        when1
    </c:when>
    <c:when test="${crage==2}">
        when2
    </c:when>
    <c:otherwise>
        when3
    </c:otherwise>
</c:choose>

<c:forEach var="i" begin="1" end="5" step="1">
    当前循环:${i}
</c:forEach>

<%
    List<User> users = new ArrayList<User>();
    users.add(new User("张三",1));
    users.add(new User("李四",2));
    users.add(new User("王五",3));
    request.setAttribute("users",users);
%>

<c:forEach  items="${users}" var="user">
    循环用户:${user.name}${user.age}
</c:forEach>

<%
    Map<Integer,User> maps = new HashMap<>();
    maps.put(1,new User("张三",1));
    maps.put(2,new User("李四",2));
    maps.put(3,new User("王五",3));
    session.setAttribute("maps",maps);
%>
<c:forEach items="${sessionScope.maps}" var="entry">
    循环用户Map:${entry.key}${entry.value.name}${entry.value.age}
</c:forEach>
</body>
</html>
